// Copyright (c) 2010 Thomas Stuefe
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#pragma once

#include "IDatabase.h"
#include "TrcLevel.h"
#include "TrcDestination.h"

namespace zencat {
namespace sqlite {


	interface class IDatabase;

	/// <summary>
    /// Central interface to all other functions in this library.
    /// </summary>
	public ref class Sqlite sealed {
	public:

		/// <summary>
		/// Creates or opens a database.
        /// </summary>
        /// <param name="databaseFile">Database file to open. If file does not exist, it is created.</param>
        /// <returns>The opened database.</returns>
		static IDatabase^ OpenDatabase(System::String^ databaseFile);

		/// <summary>
		/// Gets or sets the global trace level.
        /// </summary>
		static property TrcLevel TraceLevel {
			TrcLevel get();
			void set(TrcLevel lvl);
		}

		/// <summary>
		/// Gets or sets the trace destination.
        /// </summary>
		static property TrcDestination TraceDestination {
			TrcDestination get();
			void set(TrcDestination v);
		}

		/// <summary>
		/// Gets or sets the trace file if <see cref="TraceDestination"/> is <see cref="TrcDestination.TraceToFile"/>.
        /// </summary>
		static property String^ TraceFileName {
			String^ get();
			void set(String^ v);
		}

		/// <summary>
		/// Trace user provided text to the internal trace system. 
		/// This can be used to interleave context information with internal sqlite tracing.
        /// </summary>
        /// <remarks>
		/// To see this information, <see cref="TraceLevel"/> must 
		///  be <see cref="TrcLevel.TraceMore"/> or <see cref="TrcLevel.TraceAll"/>.
        /// </remarks>
		static void TraceLine(String^ line);

		// life cycle

		/// <summary>
		/// Gets the sqlite library initialization state.
        /// </summary>
		/// <value>true if library was initialized; false if not.</value>
		static property bool Initialized {
			bool get() {
				return _initialized; 
			}
		}

		/// <summary>
		/// Explicitly initialize the sqlite library. (see http://www.sqlite.org/c3ref/initialize.html).
        /// </summary>
		/// <remarks>
		///   If the library is not initialized explicitly, 
		///   it will be initialized on first call to <see cref="OpenDatabase"/>.
		/// </remarks>
		static void Initialize();

		/// <summary>
		/// Shutdown the sqlite library (sqlite3_shutdown()).
        /// </summary>
		static void Shutdown();

		// version information

		/// <summary>
		/// Gets the sqlite library version number.
		/// (see http://www.sqlite.org/c3ref/libversion.html)
        /// </summary>
		static property int SqliteVersionNumber {
			int get();
		}

		/// <summary>
		/// Gets the sqlite library version string.
		/// (see http://www.sqlite.org/c3ref/libversion.html)
        /// </summary>
		static property String^ SqliteVersionString {
			String^ get();
		}


	private:

		static bool _initialized = false;

	};


} // end namespace sqlite

} // end namespace zencat


/// This example shows how to open a database, create a table, insert some values, read those values.
/// \example example1.cs



